package com.core.ui.controller;

import com.core.ui.controls.ControlEdit;
import com.core.ui.controls.ControlSelect;
import com.core.ui.controls.ControlTextArea;
import com.core.utils.KeyValueDictionary;
import com.model.KeyValue;

public class DetailController {


	protected String selectControl ( String propertyName,
	                                 String caption,
	                                 KeyValue propertyValue,
	                                 KeyValueDictionary propertyValues,
	                                 boolean readonly ) {

		String result = null;

		ControlSelect controlSelect = new ControlSelect();
		controlSelect.setCaption(caption);
		controlSelect.setFormFieldName(propertyName);
		controlSelect.setData(propertyValue);
		controlSelect.setReadonly(readonly);
		controlSelect.setValues(propertyValues);
		result = controlSelect.toString();
		return result;
	}



	protected String inputControl ( String propertyName,
	                                String caption,
	                                String propertyValue,
	                                boolean readonly ) {

		String result = null;
		String data = (propertyValue == null) ? "" : propertyValue;

		ControlEdit controlEdit = new ControlEdit();
		controlEdit.setCaption(caption);
		controlEdit.setFormFieldName(propertyName);
		controlEdit.setData(data);
		controlEdit.setReadonly(readonly);
		result = controlEdit.toString();
		return result;
	}



	protected String textAreaControl ( String propertyName,
	                                   String caption,
	                                   String propertyValue,
	                                   boolean readOnly ) {

		String result = null;
		String data = (propertyValue == null) ? "" : propertyValue;

		ControlTextArea controlTextArea = new ControlTextArea();
		controlTextArea.setReadonly(readOnly);
		controlTextArea.setCaption(caption);
		controlTextArea.setData(data);
		controlTextArea.setFormFieldName(propertyName);
		controlTextArea.setRowsCount(9);
		result = controlTextArea.toString();
		return result;
	}

}
